﻿function AddRowValue(strvalue) {
    document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard__sys" + strvalue + "_RowCount").value = eval(document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard__sys" + strvalue + "_RowCount").value) + 1;
    document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard__sys" + strvalue + "_DelCount").value = 0;
}
function RemoveRow(strvalue, i) {
    document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard__sys" + strvalue + "_DelCount").value = eval(i);
    document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard__sys" + strvalue + "_RowCount").value = eval(document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard__sys" + strvalue + "_RowCount").value) - 1;
}
//-----------Added by 'Imran Gani' (copied from RakaTech) on 05-June-2013 for Org Security-----------
var selectedRadioBtnIDs = "";
var hf_selectedTreeNode = "";
$(document).ready(function () {
    getSelectedRedioBtn();
});

function getSelectedRedioBtn() {
    selectedRadioBtnIDs = "";
    var RadioList = $("input[type='radio'][id^=RB_accessrights_]:checked");
    for (var i = 0; i < RadioList.length; i++) {
        selectedRadioBtnIDs += RadioList[i].id + "#";
        hf_selectedTreeNode = document.getElementById('ctl00_ContentPlaceHolder3_User_Wizard_hih_SelectedTreeNode').value;
    }
}
function resetTreeNodeRedioBtn() {
    var RadioList = $("input[type='radio'][id^=RB_accessrights_]");
    for (var i = 0; i < RadioList.length; i++) {
        if (selectedRadioBtnIDs.indexOf(RadioList[i].id) != -1) {
            $('input:radio[id=' + RadioList[i].id + ']').prop('checked', true);
        }
    }
}
function CheckBusinessUnits(obj) {
    var ctrl_ids = document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_hih_BuCtrlIds").value.split('#');
    for (var ctrl_id = 0; ctrl_id < ctrl_ids.length; ctrl_id++) {
        if (ctrl_ids[ctrl_id] != null && ctrl_ids[ctrl_id] != undefined && ctrl_ids[ctrl_id] != "") {
            var obj_id = "ctl00_ContentPlaceHolder3_User_Wizard_dd_BuUnit_" + ctrl_ids[ctrl_id];
            if (obj_id != obj.id) {
                var BuUnit = document.getElementById(obj_id);
                if (obj.options[obj.selectedIndex].value == BuUnit.options[BuUnit.selectedIndex].value && BuUnit.options[BuUnit.selectedIndex].value != "select") {
                    alert('Business Unit Selected More than once.Reselct Other Business Unit');
                    obj.selectedIndex = 0;
                }
            }
        }
    }
}
function CheckBusinessUnitsUnSelected() {
    if (document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_DD_buid").value == "select") {
        alert('Select Attached Business Unit');
        return false;
    }
    var ctrl_ids = document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_hih_BuCtrlIds").value.split('#');
    for (var ctrl_id = 0; ctrl_id < ctrl_ids.length; ctrl_id++) {
        if (ctrl_ids[ctrl_id] != null && ctrl_ids[ctrl_id] != undefined && ctrl_ids[ctrl_id] != "") {
            var BuUnit = document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_dd_BuUnit_" + ctrl_ids[ctrl_id]);
            if (BuUnit.options[BuUnit.selectedIndex].value == "select") {
                alert('All BusinessUnit Should have one selected <b>BusnessUnit</b>');
                return false;
            }
        }
    }
}
function NodeSave(obj, val, txt) {
    if (obj.checked) {
        var val_index = document.getElementById('ctl00_ContentPlaceHolder3_User_Wizard_hih_SelectedTreeNode').value.indexOf("#" + txt + ":" + val + ":");
        if (val_index != -1) {
            val_index = document.getElementById('ctl00_ContentPlaceHolder3_User_Wizard_hih_SelectedTreeNode').value.substring(val_index, val_index + ("#" + txt + ":" + val + ":").length + 3);
            document.getElementById('ctl00_ContentPlaceHolder3_User_Wizard_hih_SelectedTreeNode').value = document.getElementById('ctl00_ContentPlaceHolder3_User_Wizard_hih_SelectedTreeNode').value.replace(val_index, "");
        }
        if (obj.value != "no") {
            document.getElementById('ctl00_ContentPlaceHolder3_User_Wizard_hih_SelectedTreeNode').value += "#" + txt + ":" + val + ":" + obj.value + "#";
        }
    }
    //   alert( document.getElementById('ctl00_ContentPlaceHolder3_User_Wizard_hih_SelectedTreeNode').value);                      
}
function ShowTreeView() {
    resetTreeNodeRedioBtn();
    document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_div_HideBackGround").style.display = "block";
    document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_div_HideBackGround").style.width = screen.width - 23;
    document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_div_HideBackGround").style.height = screen.height;
    document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_div_TreeViewModel").style.display = "block";
    document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_FinishNavigationTemplateContainerID_CancelButton").disabled = true;
    document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_FinishNavigationTemplateContainerID_FinishButton").disabled = true;
    return false;
}
function HideTreeViewWithBuUnit() {
    getSelectedRedioBtn();
    document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_div_HideBackGround").style.display = "none";
    document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_div_TreeViewModel").style.display = "none";
    AppendRow();
    document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_FinishNavigationTemplateContainerID_CancelButton").disabled = false;
    document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_FinishNavigationTemplateContainerID_FinishButton").disabled = false;
    return false;
}
function HideTreeView() {
    document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_div_HideBackGround").style.display = "none";
    document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_div_TreeViewModel").style.display = "none";
    document.getElementById('ctl00_ContentPlaceHolder3_User_Wizard_hih_SelectedTreeNode').value = hf_selectedTreeNode;
    document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_FinishNavigationTemplateContainerID_CancelButton").disabled = false;
    document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_FinishNavigationTemplateContainerID_FinishButton").disabled = false;
    return false;
}
function AppendRow() {
    var tbl = document.getElementById('ctl00_ContentPlaceHolder3_User_Wizard_htb_BuUnitGrid');
    // alert( document.getElementById('ctl00_ContentPlaceHolder3_User_Wizard_hih_SelectedTreeNode').value);   
    var val_Array = document.getElementById('ctl00_ContentPlaceHolder3_User_Wizard_hih_SelectedTreeNode').value.split("#");
    if (val_Array.length == 1 && val_Array[0] == "") {
        var table_Chklength = tbl.rows.length;
        for (var chk_length = table_Chklength - 1; chk_length > -1; chk_length--) {
            tbl.deleteRow(chk_length);
        }
    }
    else {
        var table_length = tbl.rows.length;
        for (var i = table_length - 1; i > -1; i--) {
            tbl.deleteRow(i);
        }
        var k = 1;
        var row = tbl.insertRow(0);
        row.className = "Grid_Header";
        var cell_text = row.insertCell(0);
        cell_text.className = "TreeGridViewStyle";
        cell_text.innerHTML = "Business Unit";
        var cell_access = row.insertCell(1);
        cell_access.className = "TreeGridViewStyle";
        cell_access.innerHTML = "Access Rights";

        for (var j = 0; j < val_Array.length; j++) {
            if (val_Array[j] != "") {
                row = tbl.insertRow(k);
                row.className = "Grid_Row0";
                var valtxt_Array = val_Array[j].split(":");
                cell_text = row.insertCell(0);
                cell_text.className = "TreeGridViewColumnStyle";
                cell_text.innerHTML = valtxt_Array[0];
                cell_access = row.insertCell(1);
                cell_access.className = "TreeGridViewColumnStyle";

                if (valtxt_Array[2] == "se") {
                    cell_access.innerHTML = "Self";
                }
                else if (valtxt_Array[2] == "un") {
                    cell_access.innerHTML = "Unit";
                }
                else if (valtxt_Array[2] == "su") {
                    cell_access.innerHTML = "Unit & Subunits";
                }
                k = k + 1;
            }
        }
    }
}
//----------------End for Org Security------------------

function resetRPText() {
    document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_HeaderContainer_rp_status").innerHTML = "";
}
function resetPassword() {
    var rp_randomnumber = Math.floor(Math.random() * 1001); //used to make sure that the browser sends the request to the server    
    rp_randomnumber++;
    var rp = document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_HeaderContainer_txtNewPassword").value;
    var rp1 = document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_HeaderContainer_txtConfirmPassword").value;
    var user_row_id = document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_ps_rowkey").value;
    if (rp != rp1) {
        document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_HeaderContainer_rp_status").innerHTML = "<img src='Images/error.gif' border='0'></img>&nbsp;" + "Password Mismatch";
        return;
    }
    //alert(fb);
    if (user_row_id == "") {
        document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_HeaderContainer_rp_status").innerHTML = "<img src='Images/error.gif' border='0'></img>&nbsp;" + "Invalid Settings";
        return;
    }
    if (rp == "") {
        //alert(fb);
        document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_HeaderContainer_rp_status").innerHTML = "<img src='Images/error.gif' border='0'></img>&nbsp;" + "Invalid Password";
        return;
    }
    document.getElementById("reset_password").disabled = true;
    //alert(fb);
    //return;
    try {
        var xmlHttp_fb;
        try {
            // Firefox, Opera 8.0+, Safari
            xmlHttp_fb = new XMLHttpRequest();
        }
        catch (e) {
            // Internet Explorer
            try {
                xmlHttp_fb = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e) {
                try {
                    xmlHttp_fb = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e) {
                    //alert("Your browser does not support AJAX!");
                    return false;
                }
            }
        }
        xmlHttp_fb.onreadystatechange = function () {
            if (xmlHttp_fb.readyState == 1) {
                document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_HeaderContainer_rp_status").innerHTML = "<img src='Images/load.gif' border='0'></img>&nbsp;Resetting...";
            }
            if (xmlHttp_fb.readyState == 4) {
                //document.myForm.time.value=xmlHttp.responseText;
                //document.getElementById("ctl00_ContentPlaceHolder2_lblStatus").innerHTML = "&nbsp;";
                if (xmlHttp_fb.responseText == "success")
                    document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_HeaderContainer_rp_status").innerHTML = "<img src='Images/tick5.gif' border='0'></img>&nbsp;" + "Success";
                else
                    document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_HeaderContainer_rp_status").innerHTML = "<img src='Images/error.gif' border='0'></img>&nbsp;" + xmlHttp_fb.responseText;
                document.getElementById("reset_password").disabled = false;
                document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_HeaderContainer_txtNewPassword").value = "";
                document.getElementById("ctl00_ContentPlaceHolder3_User_Wizard_HeaderContainer_txtConfirmPassword").value = "";
            }
        }
        xmlHttp_fb.open("GET", "loadTips.aspx?rp=" + escape(rp) + "&id=" + user_row_id + "&rp_rnd=" + rp_randomnumber, true);
        xmlHttp_fb.send(null);
        //setTimeout("ajaxFunction()",10000);
    }
    catch (Exxx) {
        document.getElementById("reset_password").disabled = false;
    }
}
    